﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:HyperLink ID="LoingButton" runat="server" Style="cursor: pointer">Login</asp:HyperLink>
    <DotNetAge:Dialog ID="DemoDialog" runat="server" Draggable="true" Resizable="true"
        Title="User Login" ShowModal="true" TargetID="LoingButton" OnClientOpen="resetLoginForm(this);">
        <Buttons>
            <DotNetAge:DialogButton Text="Login" OnClientClick="userLogin(this);" />
            <DotNetAge:DialogButton Text="Cancel" OnClientClick="$(this).dialog('close')" />
        </Buttons>
        <BodyTemplate>
            <div class="dna-demo-fields">
                <div class="dna-state-error  ui-corner-all" id="loginInfo" style="display: none;
                    margin: 10px;">
                </div>
                <ul>
                    <li><span>User Name:</span>
                        <input id="userName" type="text" style="width: 200px" /></li>
                    <li><span>Password:</span>
                        <input type="password" id="passWord" style="width: 200px" /></li>
                    <li>
                        <input type="checkbox" id="cbAutoLogin" checked="checked" /><label for="cbAutoLogin">AutoLogin</label></li>
                </ul>
            </div>
        </BodyTemplate>
    </DotNetAge:Dialog>

    <script type="text/javascript">
        /// <reference name="MicrosoftAjax.js"/>
        function userLogin(el) {
            var _user = $get("userName");
            var _pwd = $get("passWord");
            var _auto = $get("cbAutoLogin");
            $("#" + el.id + " input").attr("disabled", "disabled");
            Sys.Services.AuthenticationService.login(_user.value, _pwd.value, _auto.checked, null, null, userLoginSuccessful, userLoginFailed, el);
        }

        function resetLoginForm(el) {
            $get("loginInfo").style.display = 'none';
            $get("loginInfo").innerHTML = "";
            $("#" + el.id + " input").attr("disabled", "");
            $get("userName").value="";
            $get("passWord").value="";
             $get("cbAutoLogin").value="checked";
        }
        
        function userLoginSuccessful(validCredentials, userContext, methodName) {
            $("#" + userContext.id + " input").attr("disabled", "enabled");
            if (Sys.Services.AuthenticationService.get_isLoggedIn()) {
                alert("Login Success");
                $(userContext).dialog('close');
            }
            else {
                $get("loginInfo").style.display = 'block';
                $get("loginInfo").innerHTML = "Login Failed!";
            }   
           
        }

        function userLoginFailed(error, userContext, methodName) {
            $("#" + userContext.id + " input").attr("disabled", "enabled");
            $get("loginInfo").style.display = 'block';
            $get("loginInfo").innerHTML = error.get_message();
        }
    </script>

    </form>
</body>
</html>
